import netconfig from '@/config/netconfig'
import { GetRequest, PostRequest, type Response } from '@/utils/request'

export function initPairingAppliance() {
  return PostRequest('/api/installguide/v1/pairing/homeAppliances', {
    hasShowAll: netconfig.isTester,
  })
}

/**
 * 订阅未发布vib消息
 */
export function subscribeMsgUnreleasedVib(vib: string) {
  return PostRequest('/api/installguide/v1/pairing/homeAppliances/' + vib)
}

export type ApplianceInfo = {
  appearChar: string
  brand: string
  catelog: string
  catelog_name: string
  catelog_pic: string
  deviceSubType: string
  launched: number
  photo: string
  pic: string
  type: string
  vibLable: Array<string>
  step_list?: [
    {
      errors: string
    }
  ]
}
export type PairTemplateContent = {
  appearChar: number
  brand: string
  deviceSubType: string
  deviceType: string
  pairType: string
  step_list: Array<ChapterItem>
  videoUrl: string
}

export type ChapterItem = {
  button: string
  chapter: string
  chapter_code: string
  chapterby: number
  checkbox: string
  error_code: string
  errors: Array<ErrorContentItem>
  html_code: string
  orderby: number
  pic_url: string
  video: string
}
export type ErrorContentItem = {
  answer: Array<AnswerItem> | string
  cdate: string
  errorCode: string
  id: number
  question: string
  udate: string
}
export type AnswerItem = {
  order: string
  pictureUrl: string
  text: string
}

export function getVibInfo(vib: string, ignoreErrorTips?: boolean) {
  return PostRequest<ApplianceInfo>(
    '/api/installguide/v1/pairing/simple/' + vib,
    {
      hasShowAll: netconfig.isTester,
    },
    {
      ignoreErrorTips,
      noAuth: true,
    }
  )
}
export function getPairingInfo(vib: string) {
  return PostRequest<PairTemplateContent>('/api/installguide/v1/pairing/vibToTemplate/' + vib, {
    hasShowAll: netconfig.isTester,
  })
}
/**
 * 指南-置顶视频接口
 * @param vib
 * @returns
 */
export type TopVideoListByVibType = {
  hasVideo: string
  id: string
  image: string
  title: string
  url: string
}
export function getTopVideoListByVib(vib: string) {
  return GetRequest<TopVideoListByVibType[]>('/api/wx/recipes/smartCooking/getTopVideoListByVib?vib=' + vib)
}

/**
 * 指南-获取资讯接口
 * @param vib
 * @returns
 */
export type InformationVideoType = {
  documents: DocumentsType[]
  information: InformationType[]
  pairingGuidePdf: string
}
export type InformationType = {
  hasVideo: string
  id: string
  image: string
  lookCount: string
  title: string
  type: string
  url: string
}
export type DocumentsType = {
  code: string
  docTypes: string[]
  downloadUrl: string
  title: string
}
export function getInformationVideoListByVib(data: {}) {
  return PostRequest<InformationVideoType[]>('/api/wx/recipes/smartCooking/queryVibInformationNew', data)
}

/**
 * 获取首页开屏活动
 */
export enum PortalActivityJumpTypes {
  WechatArticle = 1, // 1. 微信图文
  AddAppliance = 2, // 2.添加家电
  ToLive = 3, // 3.直播间跳转
}
export type PortalActivity = {
  id?: number
  imgUrl?: string // 开屏图片
  jumpType?: PortalActivityJumpTypes // 跳转类型
  landingPage?: string // 跳转地址
  description?: string // 描述
  showNumber?: string // 同一属性用户仅可看到一个开屏
  hasShowTime?: string //已经显示的活动海报的时间
}
export type ApplianceType = {
  brand: string
  type: string
}
export function getPortalPage(appliances?: ApplianceType[] | null) {
  return PostRequest<PortalActivity>(
    '/api/content/iotplatform/portalPage',
    {
      appliances,
    },
    {
      noAuth: true,
      ignoreErrorTips: true,
    }
  )
}

export type ArticleType = {
  htmlCode: string
  title: string
  pic: string
  bannerId: number
}
/**
 * 获取文章详情
 */
export function getArticleDetail(id: string) {
  return GetRequest<ArticleType>(`/api/wx/articles/${id}`)
}

/**
 * 获取商品信息接口
 */
export type GoodsListType = {
  imgPath: string
  name: string
  price: string
  discountPrice: string
  goodsDetailsLink: string
  appId: string
}
export function getAllGoodsData(vib: string) {
  return GetRequest<GoodsListType[]>(`/api/content/cms/queryVibGoods/${vib}`)
}

/**
 * 获取富文本信息
 */
export function getRichTextData(id: string, type: string) {
  return GetRequest<{ content: string }>(`/api/content/cms/queryRichText?id=${id}&type=${type}`)
}

/**
 * 获取晶御配置页面列表
 */

export type HCConfigData = {
  icon: string
  name: string
  infoList: HCConfigInfoModel[]
}

export type HCConfigInfoModel = {
  appid: string
  description: string
  coverpic: string
  state: string
  type: string
  title: string
  url: string
  id: number
  viewTotal: number
}

export function getHcConfigList(
  page: number,
  pageSize: number,
  configType?: number
): Promise<Response<HCConfigData[]>> {
  let data: {
    [x: string]: string | number | Boolean
  } = {
    page: page,
    pageSize: pageSize,
    showAll: netconfig.isTester,
  }
  if (configType) {
    data.configType = configType
  }
  return PostRequest('/api/content/cms/getHcConfigList', data, {
    noAuth: true,
  })
}

/**
 * 获取晶御配置详情
 */
export type HCConfigDetailData = {
  url: string
  appid: string
}

export function getHcConfigDetail(id: number): Promise<Response<HCConfigDetailData>> {
  return PostRequest(
    '/api/content/cms/getHcConfigDetail',
    {
      id: id,
    },
    { noAuth: true }
  )
}

/**
 * 获取搜索推荐列表
 */
type HotConfigObject = {
  search_recommendation: string[]
}

export function getHotHcConfigList(): Promise<Response<HotConfigObject[]>> {
  return PostRequest('/api/content/cms/getHotHcConfigList', void 0, {
    noAuth: true,
  })
}

/**
 * 获取联想词关联列表
 */
export type FuzzyListType = {
  total: 34
  pageNum: 1
  pageSize: 500
  ask: {
    title: string
    jumpLink: string
  }[]
  rows: string[]
}
export function getFuzzyList(data: {}) {
  return GetRequest<FuzzyListType>(`/api/content/cms/getAssociativeWords`, data)
}

/**
 * 获取联想词关联列表
 */
export type SearchContentType = {
  siemensAppid: string
  boschAppid: string
  ask: {
    items: SearchAskItemType[]
  }
  itemSales: {
    salesData: SearchSalesType[]
    salesNum: number
    total: number
  }
}
export type SearchAskItemType = {
  brandId: string
  description: string
  jumpLink: string
  sort: string
  title: string
  titleSuffix: string
  type: string
}
export type SearchSalesType = {
  sort: number
  categoryName: string
  categoryId: string
  itemSaleList: SearchSalesItemType[]
}
export type SearchSalesItemType = {
  marketPrice: string
  jumpLink: string
  saleImag: string
  isCleaningServices: number
  classId: number
  crossedPrice: string
  esScore: number
  imgPath: string
  name: string
  showFirstOrderFlag: number
  typeId: number
  id: number
  cids: string
  brand: string
}
export function getSearchContent(data: {}) {
  return GetRequest<SearchContentType>(`/api/content/cms/searchWord`, data)
}
